﻿using JzSport.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace JzSport.Api
{
    class DeleteMessageAction : AuthPostAction<DeleteMessageParams,
        DeleteMessageResult>
    {
        protected override ActionResult<DeleteMessageResult> OnExecute(ActionContext context, 
            SysParameters sysParameters,
            DeleteMessageParams opParams)
        {
            ServiceResult<string> serviceResult = new MessageService().DeleteMessage(context.AccountId,
                opParams.MessageId);

            DeleteMessageResult actionResult = new DeleteMessageResult();

            if (serviceResult.ErrorCode == ErrorCode.NoError)
            {
                return new ActionResult<DeleteMessageResult>(true, serviceResult.ErrorCode,
                    ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
            }
            return new ActionResult<DeleteMessageResult>(false, serviceResult.ErrorCode,
                    ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
        }
    }

    public class DeleteMessageParams : IActionParams
    {
        /// <summary>
        /// 消息id
        /// </summary>
        public Guid MessageId { get; set; }

        public void ParseQueryString(HttpRequest request)
        {
            this.MessageId = new Guid(request.QueryString["op:MessageId"]);
        }

        public void ParseForm(HttpRequest request)
        {
            this.MessageId = new Guid(request.Form["op:MessageId"]);
        }
    }

    public class DeleteMessageResult
    {
    }
}
